// 宏任务 setTimeout\setInterval\IO时间\setImmediate\close事件
// 微任务 Promise.then\process.nextTick\queueMicrotask
// nextTick在微任务中比then和queueMicrotask优先执行
// 先执行setTimeout\再执行setImmediate

/**
 * main script 主线程
 * nextTick 微任务——优先
 * other micro 微任务
 * timers 宏任务——优先
 * check 宏任务
 *
 */

async function async1() {
  console.log("async1 start");
  await async2();
  console.log("async1 end");
}

async function async2() {
  console.log("async2");
}

console.log("script start");

setTimeout(function () {
  console.log("setTimeout0");
}, 0);

setTimeout(function () {
  console.log("setTimeout2");
}, 300);

setImmediate(() => console.log("setImmediate"));

process.nextTick(() => console.log("nextTick1"));

async1();

process.nextTick(() => console.log("nextTick2"));

new Promise(function (resolve) {
  console.log("promise1");
  // 这里不会阻断
  resolve();
  console.log("promise2");
}).then(function () {
  console.log("promise3");
});

console.log("script end");

// script start
// async1 start
// async2
// promise1
// promise2
// script end
// nexttick1
// nexttick2
// async1 end
// promise3
// settimeout0
// setImmediate
// setTimeout2
